<{css src='style.css' app='inventorydepth'}>

<div class=''>
    <div id='download-msg'>
        <{if $url}>
            <div class="console_handle" >
                <span class="flt" style="color:#333; margin-left:10px;">等待<{$title}></span>
            </div>
            <div class="clear loadpart">	
                <div  class="loader"><strong class="appNum" style='top:-50px;'>0%</strong></div>
            </div>
            <div class='waiting-download' style='display:none;' name="<{$title}>" ></div>
            <div class='clear'></div>
            <div id='result'></div>
        <{else}>
            <div>参数错误，同步失败！！！</div>
        <{/if}>

    </div>
</div>
<{area inject='.mainFoot'}>
<div class='table-action'>
<{button label='确定' isCloseDialogBtn="true"}>
</div>
<{/area}>
<form id='download-form'>
    <{$inputhtml}>
</form> 
<{if $url}>
<script type="text/javascript">
void function(){
    var loader = $E('#download-msg .waiting-download');
    if ($defined(loader))
    {
        function request(page,item){
            new Request.JSON({
                url:"<{$url}>&page="+page,
                data:$('download-form'),
                method:'post',
                async:true,
                onRequest:function(){
                    $E('#download-msg .console_handle .flt').setHTML('正在同步【'+item.get('name')+'】...');
                },
                onComplete:function(resp){
                    if (resp.error)
                    {
                        isDownload = false;
                        $('result').addClass('error').setHTML('同步终止：'+resp.error);
                        $E('#download-msg .console_handle .flt').setHTML('终止同步【'+item.get('name')+'】！');
                        return ;
                    }
                    if (resp.errormsg)
                    {
                        var errorDiv = new Element('div',{html:'同步成功，但存在以下问题：<br/>'+resp.errormsg});
                        $('result').addClass('notice').adopt(errorDiv);
                    }
                    $E('#download-msg .loadpart .appNum').setHTML(resp.downloadRate+'%');
                    $E('#download-msg .loadpart .loader').setStyle('width',resp.downloadRate+'%');
                    if (resp.downloadStatus == 'finish')
                    {
                        $E('#download-msg .console_handle .flt').setHTML('同步【'+item.get('name')+'】完成！');

                        if ("<{$refresh}>")
                        {
                            finderGroup['<{$env.get.finder_id}>'].refresh();
                        }
                        return ;
                    }
                    page++;
                    request(page,item);
                },
                onFailure:function(){
                        isDownload = false;
                        $('result').addClass('error').setHTML('同步终止：请求服务器失败！');
                        $E('#download-msg .console_handle .flt').setHTML('终止同步【'+item.get('name')+'】！');
                        return ;
                }
            }).send();
            return false;
        }

        $('result').removeClass('error').removeClass('notice').empty();
        request(1,loader);
    }
}();
</script>
<{/if}>